<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="友情链接">
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div class="form-actions">
                <a href="javascript:;" class="button button-success">
                    <i class="icon-plus-sign icon-white"></i> 查询
                </a>
                <a href="javascript:add()" class="button button-success">
                    <i class="icon-plus-sign icon-white"></i> 添加
                </a>
                <a class="button button-danger" onclick="return delFunction();">
                    <i class="icon-remove-sign icon-white"></i> 删除
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<#-------------------------------------------------新增表单start------------------------------------------------>
<div id="addContent" style="display: none">
    <form action="${basepath}/manage/navigation/insertJson" id="addForm" class="form-horizontal" method="post">
        <input type="hidden" class="input-normal control-text" name="id"/>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">名称：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="name">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">打开方式：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" ">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">位置：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">顺序：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="order1"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">地址：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="http"/>
                </div>
            </div>
        </div>
    </form>
</div>
<#-------------------------------------------------新增表单 end------------------------------------------------->
<#-------------------------------------------------编辑表单start------------------------------------------------>
<div id="editContent" style="display: none">
    <form action="${basepath}/manage/navigation/insertJson" id="editForm" class="form-horizontal" method="post">
        <input type="hidden" class="input-normal control-text" name="id"/>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">名称：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="name">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">打开方式：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" ">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">位置：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">顺序：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="order1"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">地址：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="http"/>
                </div>
            </div>
        </div>
    </form>
<#-------------------------------------------------编辑表单 end------------------------------------------------->


<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '名称', dataIndex: 'name', width: '15%'},
                {title: '链接', dataIndex: 'http', width: '15%'},
                {title: '打开方式', dataIndex: 'target', width: '15%'},
                {title: '位置', dataIndex: 'position', width: '15%'},
                {title: '顺序', dataIndex: 'order1', width: '15%'},
                {
                    title: '操作', dataIndex: 'id', width: '15%', renderer: function (value) {
                    <#if checkPrivilege("/manage/navigation/edit")>
                        return '<a href="javascript:edit(' +value+ ')">编辑</a>';
                    <#else>
                        return "";
                    </#if>
                }
                }
            ];
    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#status").val()
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*-------------------------------------------------新增表单处理start-------------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();
    var addDialog = new BUI.Overlay.Dialog({
        title: '新增友情链接',
        width: 500,
        height: 320,
        contentId: 'addContent',
        success: function () {
            addForm.ajaxSubmit();
        }
    });
    //添加按钮事件
    function add() {
        addDialog.show();
    }
    /*-------------------------------------------------新增表单处理 end--------------------------------------------*/
    /*----------------------------------------------编辑表单处理 begin------------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType : 'ajax',
        callback : function(data){
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '编辑友情链接',
        width: 500,
        height: 320,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //编辑按钮事件
    function edit(id) {
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"${basepath}/manage/navigation/toEditJson",
            data:{id:id},
            success:function(data) {
                var form =$("#editForm")[0];
                BUI.FormHelper.setFields(form,data.data);
                editDialog.show();
            }
        });
    }
    /*----------------------------------------------编辑表单处理 end------------------------------------*/

    //删除选中的记录
    function delFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/navigation/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }

</script>
<#--<form action="${basepath}/manage/navigation" method="post" theme="simple">-->
<#--<table class="table table-bordered">-->
<#--<tr>-->
<#--<td colspan="6">-->
<#--<button method="selectList" class="btn btn-primary" onclick="selectList(this)">-->
<#--<i class="icon-search icon-white"></i> 查询-->
<#--</button>-->
<#---->
<#--<a href="toAdd" class="btn btn-success">-->
<#--<i class="icon-plus-sign icon-white"></i> 添加-->
<#--</a>-->
<#---->
<#--<button method="deletes" class="btn btn-danger" onclick="return submitIDs(this,'确定删除选择的记录?');">-->
<#--<i class="icon-remove-sign icon-white"></i> 删除-->
<#--</button>-->
<#---->
<#--<div style="float: right;vertical-align: middle;bottom: 0px;top: 10px;">-->
<#--<#include "/manage/system/pager.ftl" >-->
<#--</div>-->
<#--</td>-->
<#--</tr>-->
<#--</table>-->
<#---->
<#--<div class="alert alert-info" style="margin-bottom: 2px;text-align: left;">友情链接会自动显示到门户的最底部。友情链接的地址不要以“http://”开头。</div>-->
<#--<table class="table table-bordered table-hover">-->
<#--<tr style="background-color: #dff0d8">-->
<#--<th width="20"><input type="checkbox" id="firstCheckbox" /></th>-->
<#--<th style="display: none;">编号</th>-->
<#--<th >名称</th>-->
<#--<th >链接</th>-->
<#--<th >打开方式</th>-->
<#--<th >位置</th>-->
<#--<th >顺序</th>-->
<#--<th nowrap="nowrap">操作</th>-->
<#--</tr>-->
<#--<#list pager.list as item>-->
<#--<tr>-->
<#--<td><input type="checkbox" name="ids"-->
<#--value="${item.id!""}" /></td>-->
<#--<td style="display: none;">&nbsp;${item.id!""}</td>-->
<#--<td>&nbsp;<a href="http://${item.http!""}" target="_blank">${item.name!""}</a></td>-->
<#--<td>&nbsp;${item.http!""}</td>-->
<#--<td>&nbsp;${item.target!""}</td>-->
<#--<td>&nbsp;${item.position!""}</td>-->
<#--<td>&nbsp;${item.order1!""}</td>-->
<#--<td><a href="toEdit?id=${item.id}">编辑</a></td>-->
<#--</tr>-->
<#--</#list>-->

<#--<tr>-->
<#--<td colspan="71" style="text-align: center;">-->
<#--<#include "/manage/system/pager.ftl" ></td>-->
<#--</tr>-->
<#--</table>-->

<#--</form>-->
</@page.pageBase>